set maxvar 10000

 
use "/Users/jimgolby/Desktop/ZB - Confidence Book/Data/gss7221_r1b2.dta"

*****Define Variables*****
generate conmil = .
replace conmil = 0 if conarmy > 1 & conarmy < 4
replace conmil = 1 if conarmy == 1

generate PID3 = .
replace PID3 = 1 if partyid < 3
replace PID3 = 2 if partyid == 3
replace PID3 = 3 if partyid > 3 & partyid < 7

generate dem = 0
replace dem = 1 if PID3 == 1
generate rep = 0
replace rep = 1 if PID3 == 3

generate strongdem = 0
replace strongdem = 1 if partyid == 0

generate strongrep = 0
replace strongrep = 1 if partyid == 6

generate IDEO3 = .
replace IDEO3 = -1 if polviews < 4 & polviews > 0
replace IDEO3 = 0 if polviews == 4
replace IDEO3 = 1 if polviews > 4 & polviews < 8

generate white = 0
replace white = 1 if race == 1
generate black = 0
replace black = 1 if race == 2

generate man = 0
replace man = 1 if gender1 == 1
generate woman = 0
replace woman = 1 if gender1 == 2

generate income5 =.
replace income5 = 1 if realinc < 25000
replace income5 = 2 if realinc > 24999 & realinc < 50000
replace income5 = 3 if realinc > 49999 & realinc < 85000
replace income5 = 4 if realinc > 84999 & realinc < 150000
replace income5 = 5 if realinc > 149999

generate education = 0
replace education = 1 if educ == 12
replace education = 2 if educ > 12 & educ < 16
replace education = 3 if educ == 16
replace education = 4 if educ > 16

generate waryear = 0
replace waryear = 1 if year < 1976
replace waryear = 1 if year == 1991
replace waryear = 1 if year > 2000

generate dempres = 0
replace dempres = 1 if year > 1976 & year < 1981
replace dempres = 1 if year > 1992 & year < 2001
replace dempres = 1 if year > 2008 & year < 2017

generate reppres = 0
replace reppres = 1 if year < 1977
replace reppres = 1 if year > 1980 & year < 1993
replace reppres = 1 if year > 2000 & year < 2009
replace reppres = 1 if year > 2016

egen meanmil = mean(conmil), by(year)

egen meandem = mean(conmil) if PID3 == 1, by(year)
egen meanrep = mean(conmil) if PID3 == 3, by(year)
egen meanind = mean(conmil) if PID3 == 2, by(year)

mean meandem if dempres == 1
mean meandem if dempres == 0
mean meanrep if reppres == 1
mean meanrep if reppres == 0

mean meanrep, over(year)
mean meandem, over(year)

egen meanlib = mean(conmil) if IDEO3 == -1, by(year)
egen meanmod = mean(conmil) if IDEO3 == 0, by(year)
egen meancon = mean(conmil) if IDEO3 == 1, by(year)

egen meanvlib = mean(conmil) if polviews == 1, by(year)
egen meanvcon = mean(conmil) if polviews == 7, by(year)

egen meanwhite = mean(conmil) if white == 1, by(year)
egen meanblack = mean(conmil) if black == 1, by(year)

egen meanman = mean(conmil) if man == 1, by(year)
egen meanwoman = mean(conmil) if woman == 1, by(year)

egen meanideodem = mean(IDEO3) if PID3 == 1, by(year)
egen meanideorep = mean(IDEO3) if PID3 == 3, by(year)
egen meanideoind = mean(IDEO3) if PID3 == 2, by(year)

egen meaninc1 = mean(conmil) if income5 == 1, by(year)
egen meaninc2 = mean(conmil) if income5 == 2, by(year)
egen meaninc3 = mean(conmil) if income5 == 3, by(year)
egen meaninc4 = mean(conmil) if income5 == 4, by(year)
egen meaninc5 = mean(conmil) if income5 == 5, by(year)
egen meaninc15 = mean(conmil) if income5 < 3, by(year)
egen meaninc25 = mean(conmil) if income5 > 3, by(year)

generate conscotus = .
replace conscotus = 0 if conjudge > 1 & conjudge < 4
replace conscotus = 1 if conjudge == 1

generate concongress = .
replace concongress = 0 if conlegis > 1 & conlegis < 4
replace concongress = 1 if conlegis == 1

generate conmedia = .
replace conmedia = 0 if conpress > 1 & conpress < 4
replace conmedia = 1 if conpress == 1

generate conbank = .
replace conbank = 0 if confinan > 1 & confinan < 4
replace conbank = 1 if confinan == 1

generate conpres = .
replace conpres = 0 if confed > 1 & confed < 4
replace conpres = 1 if confed == 1

generate conorglabor = .
replace conorglabor = 0 if conlabor > 1 & conlabor < 4
replace conorglabor = 1 if conlabor == 1

generate conbigbus = .
replace conbigbus = 0 if conbus > 1 & conbus < 4
replace conbigbus = 1 if conbus == 1

generate conrelig = .
replace conrelig = 0 if conclerg > 1 & conclerg < 4
replace conrelig = 1 if conclerg == 1

generate conedu = .
replace conedu = 0 if coneduc > 1 & coneduc < 4
replace conedu = 1 if coneduc == 1

generate conmedicine = .
replace conmedicine = 0 if conmedic > 1 & conmedic < 4
replace conmedicine = 1 if conmedic == 1

generate contele = .
replace contele = 0 if contv > 1 & contv < 4
replace contele = 1 if contv == 1

generate conscience = .
replace conscience = 0 if consci > 1 & consci < 4
replace conscience = 1 if consci == 1

egen meancongress = mean(concongress), by(year)
egen meanscotus = mean(conscotus), by(year)
egen meanmedia = mean(conmedia), by(year)
egen meanpres = mean(conpres), by(year)
egen meanscience = mean(conscience), by(year)
egen meanbank = mean(conbank), by(year)
egen meanorglabor = mean(conorglabor), by(year)
egen meanbigbus = mean(conbigbus), by(year)
egen meanrelig = mean(conrelig), by(year)
egen meanedu = mean(conedu), by(year)
egen meanmedicine = mean(conmedicine), by(year)

egen meancongressd = mean(concongress) if dem == 1, by(year)
egen meanscotusd = mean(conscotus) if dem == 1, by(year)
egen meanmediad = mean(conmedia) if dem == 1, by(year)
egen meanpresd = mean(conpres) if dem == 1, by(year)
egen meanscienced = mean(conscience) if dem == 1, by(year)
egen meanbankd = mean(conbank) if dem == 1, by(year)
egen meanorglabord = mean(conorglabor) if dem == 1, by(year)
egen meanbigbusd = mean(conbigbus) if dem == 1, by(year)
egen meanreligd = mean(conrelig) if dem == 1, by(year)
egen meanedud = mean(conedu) if dem == 1, by(year)
egen meanmedicined = mean(conmedicine) if dem == 1, by(year)

egen meancongressr = mean(concongress) if rep == 1, by(year)
egen meanscotusr = mean(conscotus) if rep == 1, by(year)
egen meanmediar = mean(conmedia) if rep == 1, by(year)
egen meanpresr = mean(conpres) if rep == 1, by(year)
egen meansciencer = mean(conscience) if rep == 1, by(year)
egen meanbankr = mean(conbank) if rep == 1, by(year)
egen meanorglaborr = mean(conorglabor) if rep == 1, by(year)
egen meanbigbusr = mean(conbigbus) if rep == 1, by(year)
egen meanreligr = mean(conrelig) if rep == 1, by(year)
egen meanedur = mean(conedu) if rep == 1, by(year)
egen meanmediciner = mean(conmedicine) if rep == 1, by(year)

generate confidence = (conscotus + concongress + conmedia + conpres + conedu + conmedicine + conscience)/7
egen meanconfidence = mean(confidence), by(year)
egen meandemconfidence = mean(confidence) if dem == 1, by(year)
egen meanrepconfidence = mean(confidence) if rep == 1, by(year)
********************

********************
*****Figure 4.1*****
twoway (line meanmil year, lcolor(gs0) lwidth(medium) lpattern(solid)) (line meanscience year, lcolor(gs1) lwidth(medium) lpattern(dash)) (line meanmedicine year, lcolor(gs2) lwidth(medthick) lpattern(dot)) (line meanscotus year, lcolor(gs3) lwidth(medium) lpattern(longdash_dot)) (line meanedu year, lcolor(gs4) lwidth(medium) lpattern(shortdash)) (line meanpres year, lcolor(gs5) lwidth(medium) lpattern(shortdash_dot)) (line meancongress year, lcolor(gs6) lwidth(medium) lpattern(tight_dot)) (line meanmedia year, lcolor(gs7) lwidth(medium) lpattern(longdash_shortdash)), legend(on order(1 "Military" 2 "Science" 3 "Medical System" 4 "Supreme Court" 5 "Education System" 6 "Presidency" 7 "Congress" 8 "Media") size(vsmall)) ytitle(% Expressing Confidence) ytitle(, size(small) margin(small)) yscale(range(0 1)) ylabel(#6) ylabel(, labsize(vsmall)) name(fig41u, replace) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) xtitle(Year) xtitle(, size(small)) xlabel(, labsize(vsmall))


*****Figure 4.2*****
twoway (line meanmil year, lcolor(gs0) lwidth(medium) lpattern(solid)) (line meanconfidence year, lcolor(gs1) lwidth(medium) lpattern(dash)), legend(on order(1 "Military" 2 "Other Federal Institutions") size(vsmall)) ytitle(% Expressing Confidence) ytitle(, size(small) margin(small)) yscale(range(0 1)) ylabel(#6) ylabel(, labsize(vsmall)) name(fig42u, replace) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) xtitle(Year) xtitle(, size(small)) xlabel(, labsize(vsmall))


*****Figure 4.3*****
quietly logit conmil confidence black woman education age dem rep year waryear
quietly mgen, atmeans at(confidence=(0(.1)1) black=(0) woman=(0) dem=(0) rep=(0) year=(1974) waryear=(0))
quietly graph twoway line _ll1 _ul1 _pr1 _confidence, scheme(sj) yscale(range(0 1)) ylabel(#5) || histogram confidence if year == 1975, fraction ytitle(Predicted Confidence in the Military) xtitle(Confidence in Other Institutions (1974)) name(pica, replace) legend(on order(1 "95% Lower Limit" 2 "95% Upper Limit" 3 "Military" 4 "Other Institutions") size(vsmall)) ytitle(, size(small) margin(small)) ylabel(, labsize(vsmall)) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) xtitle(, size(small)) xlabel(, labsize(vsmall))


quietly logit conmil confidence black woman education age dem rep year waryear
quietly mgen, atmeans at(confidence=(0(.1)1) black=(0) woman=(0) dem=(0) rep=(0) year=(2021) waryear=(1)) stub(c)
quietly graph twoway line cll1 cul1 cpr1 cconfidence, scheme(sj) yscale(range(0 1)) ylabel(#5) || histogram confidence if year == 2021, fraction ytitle(Predicted Confidence in the Military) xtitle(Confidence in Other Institutions (2021)) name(picc, replace) legend(on order(1 "95% Lower Limit" 2 "95% Upper Limit" 3 "Military" 4 "Other Institutions") size(vsmall)) ytitle(, size(small) margin(small)) ylabel(, labsize(vsmall)) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) xtitle(, size(small)) xlabel(, labsize(vsmall))

graph combine pica picc, graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(none) lpattern(solid) lalign(outside) ifcolor(none)) name(fig43u, replace)

*****Figure 4.4*****
quietly twoway (line meandem year, lcolor(gs0) lwidth(medium) lpattern(solid)) (line meanscienced year, lcolor(gs1) lwidth(medium) lpattern(dash)) (line meanmedicined year, lcolor(gs2) lwidth(medthick) lpattern(dot)) (line meanscotusd year, lcolor(gs3) lwidth(medium) lpattern(longdash_dot)) (line meanedud year, lcolor(gs4) lwidth(medium) lpattern(shortdash)) (line meanpresd year, lcolor(gs5) lwidth(medium) lpattern(shortdash_dot)) (line meancongressd year, lcolor(gs6) lwidth(medium) lpattern(tight_dot)) (line meanmediad year, lcolor(gs7) lwidth(medium) lpattern(longdash_shortdash)), legend(on order(1 "Military" 2 "Science" 3 "Medical System" 4 "Supreme Court" 5 "Education System" 6 "Presidency" 7 "Congress" 8 "Media") size(vsmall)) ytitle(% Expressing Confidence) ytitle(, size(small) margin(small)) yscale(range(0 1)) ylabel(#6) ylabel(, labsize(vsmall)) name(picdeminst, replace) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) xtitle(Year) xtitle(, size(small)) xlabel(, labsize(vsmall))

quietly twoway (line meanrep year, lcolor(gs0) lwidth(medium) lpattern(solid)) (line meansciencer year, lcolor(gs1) lwidth(medium) lpattern(dash)) (line meanmediciner year, lcolor(gs2) lwidth(medthick) lpattern(dot)) (line meanscotusr year, lcolor(gs3) lwidth(medium) lpattern(longdash_dot)) (line meanedur year, lcolor(gs4) lwidth(medium) lpattern(shortdash)) (line meanpresr year, lcolor(gs5) lwidth(medium) lpattern(shortdash_dot)) (line meancongressr year, lcolor(gs6) lwidth(medium) lpattern(tight_dot)) (line meanmediar year, lcolor(gs7) lwidth(medium) lpattern(longdash_shortdash)), legend(on order(1 "Military" 2 "Science" 3 "Medical System" 4 "Supreme Court" 5 "Education System" 6 "Presidency" 7 "Congress" 8 "Media") size(vsmall)) ytitle(% Expressing Confidence) ytitle(, size(small) margin(small)) yscale(range(0 1)) ylabel(#6) ylabel(, labsize(vsmall)) name(picrepinst, replace) graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(black) lpattern(solid) lalign(outside) ifcolor(none)) xtitle(Year) xtitle(, size(small)) xlabel(, labsize(vsmall))

graph combine picdeminst picrepinst, graphregion(fcolor(white) lcolor(white) lwidth(thin) lalign(outside) ifcolor(none) ilcolor(none)) plotregion(fcolor(white) lcolor(none) lpattern(solid) lalign(outside) ifcolor(none)) name(fig44u, replace)
**********************
